# -*- encoding:utf-8 -*-
from demo import app
from flask import g, session, request
from flask import render_template
from functools import wraps
import os, sys
import re

def get_module(path, current_module = 'controllers', parent_module = 'demo'):
    """
        动态加载全部controllers

    """
    module_name = '%s.%s' % (parent_module, current_module)
    path = os.path.join(path, current_module)
    files = os.listdir(path)
    files.reverse()
    for item in files:
        if os.path.isdir(os.path.join(path, item)):
            get_module(path, item, module_name)
        else:
            res = re.match(r'((?!__init__).*)\.py$', item)
            if not res:
                continue
            m = res.group(1)
            __import__('%s.%s' % (module_name, m))


@app.errorhandler(404)
def to_404(error):
    return '<h2>页面飞走了</h2>'



